#include <QtTriggerEditorFactory.h>
#include <QFileDialog>
#include <EDesignerCore.h>
#include <ModeControlDialog.h>


QtTriggerEditorFactory::QtTriggerEditorFactory(QObject *parent) : QtAbstractEditorFactory<QtTriggerEditorManager>(parent)
{

}

QtTriggerEditorFactory::~QtTriggerEditorFactory()
{

}


void QtTriggerEditorFactory::connectPropertyManager(QtTriggerEditorManager *manager)
{
    //connect(manager, SIGNAL(valueChanged(QtProperty*,double)),this, SLOT(slotPropertyChanged(QtProperty*,double)));
    //std::cout<<"QtTriggerEditorFactory::connectPropertyManager"<<" connected with manager"<<std::endl;

}

QWidget *QtTriggerEditorFactory::createEditor(QtTriggerEditorManager *manager, QtProperty *property, QWidget *parent)
{
    QPushButton* triggerButton = new QPushButton(parent);
    triggerButton->setText("push");
    m_propertyToWidget[property] = triggerButton;
    m_WidgetToProperty[triggerButton] = property;
    connect(triggerButton, SIGNAL( clicked (bool)),this, SLOT(slotButtonClicked(bool)));
    return triggerButton;
}

void QtTriggerEditorFactory::disconnectPropertyManager(QtTriggerEditorManager *manager)
{

}

//void QtTriggerEditorFactory::slotSetValue(const QVarintTrigger &trigger)
//{
//    QObject* sender = QObject::sender();
//    UrlEditWidget* url_edit_widget = qobject_cast<UrlEditWidget*>(sender);
//    if(url_edit_widget != NULL)
//    {
//        QtProperty *property = m_WidgetToProperty[url_edit_widget];
//        QtUrlEditorManager* manager = propertyManager(property);
//        manager->setValue(property, trigger);
//    }
//}
void QtTriggerEditorFactory::slotButtonClicked(bool)
{
    QObject* sender = QObject::sender();
    QPushButton* pushButton = qobject_cast<QPushButton*>(sender);
    if(pushButton != NULL)
    {
        QtProperty *property = m_WidgetToProperty[pushButton];
        QtTriggerEditorManager* manager = propertyManager(property);
        manager->setValueByButton(property);
    }
}

#include "moc_QtTriggerEditorFactory.cxx"
